package com.service.impl;

import com.bean.entity.Evaluate;
import com.bean.pojo.PageAssistant;
import com.dao.EvaluateMapper;
import com.service.EvaluateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 学生评价等级基础业务逻辑实现
 */
@Service
public class EvaluateServiceImpl implements EvaluateService {

    @Autowired
    private EvaluateMapper evaluateMapper;

    public int save(Evaluate t) throws Exception {
        return evaluateMapper.insert(t);
    }

    public int remove(Evaluate t) throws Exception {
        return evaluateMapper.delete(t);
    }

    public int modify(Evaluate t) throws Exception {
        return evaluateMapper.update(t);
    }

    public Evaluate unique(Evaluate t) throws Exception {
        List<Evaluate> evaluateList = evaluateMapper.select(t);
        if (evaluateList.size()!=1) throw new Exception("您要查询的学生分数暂未找到！");
        return evaluateList.get(0);
    }

    public List<Evaluate> query(Evaluate t) {
        return evaluateMapper.select(t);
    }

    public PageAssistant<Evaluate> queryByPage(Map<String, Object> map, PageAssistant<Evaluate> pa) {
        //查询并设置总记录数
        pa.setCount(evaluateMapper.selectCount(map));
        //添加分页参数
        map.put("startCode", pa.getStartCode());
        map.put("pageSize", pa.getPageSize());
        //查询并设置页面内容
        pa.setItems(evaluateMapper.selectByPage(map));
        return pa;
    }
}
